package com.demo.controller.common;

import com.demo.HelloApplication;
import com.demo.controller.menu.ConfigController;
import com.demo.util.ConfigLoader;
import com.demo.util.ControllerManager;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;
import java.util.Properties;
import java.util.ResourceBundle;

import static com.demo.util.ControllerManager.mainController;

public class MenuController implements Initializable {

    @FXML
    protected void onSMTPConfigClick() throws IOException {
        // 加载配置窗口
        FXMLLoader configLoader = new FXMLLoader(HelloApplication.class.getResource("menu_config.fxml"));
        Stage configStage = new Stage();
        configStage.setScene(new Scene(configLoader.load()));
        configStage.setTitle("配置参数");

        ConfigController configController = configLoader.getController();
        Properties props = ConfigLoader.getMailProperties();
        configController.setProperties(props);
        configController.setStage(configStage);
        configStage.setTitle("Test!");
        configStage.show();
    }

    @FXML
    protected void onCloseClick() {
        mainController.onCloseClick();
        System.out.println("close");
    }

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        ControllerManager.menuController = this;
    }
}
